import Axios from 'axios';
import { Loading } from 'element-ui';
// import vm from "../main"
// import store from "../store"
const ConfigBaseURL = "/api";
//
const Service = Axios.create({
    baseURL: ConfigBaseURL,  //作用在请求时候给url属性前加一个前缀
    timeout: 8000,
});
// Service.defaults.headers.post["Content- Type"] = "application/json;charset=UTF-8";
let loading
Service.interceptors.request.use(
    config => {
        // console.log('请求拦截');
        // if (store.getters.token) {
        let token = JSON.parse(sessionStorage.getItem('token'))
        config.headers.token = token  //这里读取vuex里的tonken值并携带
        // }
        loading = Loading.service({
            lock:true,
            text:'拼命加载中...',
            background:'rgba(0,0,0,0.7)'
        })
        return config;
    });
Service.interceptors.response.use(res => {
        // console.log('响应拦截');
        if (res.data.token) {
            // store.dispatch("setToken", res.data.token)
        }
        loading.close()
        return res;
    },
    error => {
        const msg = error.Message !== undefined ? error.message : '';
        Message({
            message: "网络错误" + msg,
            type: 'error',
            duration: 3 * 1000
        });
        loadingInstance.close();
        return Pormise.reject(error);
    }
);
export default
Service; // 调用者 ---> ../service/index.js --> getList